<template>
  <div class="container-big">
    <ul class="tablist">
      <li :class="active==index?`active`:``" @click="getAcitve(index)" v-for="(item,index) in tablist">
        <svg-icon :icon-class="item.icon" v-if="active ==index"/>
        <svg-icon :icon-class="item.activeIcon" v-else/>
        {{ item.label }}
      </li>
    </ul>
    <div class="content-big">
      <div class="content-left">
        <div class="left-title">分组和标签</div>
        <div class="flex">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="标签组/标签名" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
          <el-button icon="el-icon-plus" size="small"></el-button>
        </div>
        <ul class="treeList">
          <li v-for="(item,index) in treeList" @click="isOpenNode(index)">
            <div class="title">
              <div class="title-left">
                <transition name="fade">
                  <i class="el-icon-caret-right" v-if="!item.showChildren"></i>
                  <i class="el-icon-caret-bottom" v-else></i>
                </transition>
                {{ item.label }}
              </div>
              <div class="add">
                <i class="el-icon-plus"></i>
              </div>
            </div>
            <transition name="fade">
              <div v-show="item.showChildren">
                <dl v-if="item.children && item.children.length>0" v-for="(sitem,sindex) in item.children">
                  <dd :class="treeActive==index && smallActive==sindex?`treeActive`:``" @click.stop="getTreeActive(index,sindex)"><i class="el-icon-caret-right" style="opacity: 0"></i>{{ sitem.label }}
                    <div class="number">0</div>
                  </dd>
                </dl>
              </div>
            </transition>


          </li>
        </ul>
      </div>
      <div class="content-tabel">
        <div class="content-title">客户列表</div>
        <div class="form-big">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="130px">
            <el-button size="small" type="primary" icon="el-icon-plus" @click="handerAdd('add')" v-hasPermi="['IntelligentOperationList:autoLabel']">自动打标签</el-button>
            <el-button size="small" type="primary" icon="el-icon-plus" plain @click="handleAddUser" v-hasPermi="['IntelligentOperationList:addUser']">添加客户</el-button>
            <el-form-item prop="userName1">
              <el-select v-model="queryParams.id" placeholder="企微号分组" style="width: 150px;">
                <el-option
                  v-for="item in userList"
                  :key="Number(item.value)"
                  :label="item.label"
                  :value="Number(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="userName3">
              <el-select v-model="queryParams.id" placeholder="所属企微号" style="width: 150px;">
                <el-option
                  v-for="item in userList"
                  :key="Number(item.value)"
                  :label="item.label"
                  :value="Number(item.value)">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="userName1">
              <div class="search" style="width: 200px;">
                <el-input v-model="queryParams.userName1" size="small" placeholder="标签组/标签名" clearable/>
                <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
              </div>
            </el-form-item>

          </el-form>
          <div class="group-btn">
            <el-button size="small">任务中心</el-button>
            <el-button size="small" @click="handleViewData">查看数据</el-button>
            <!--                <el-button size="medium" @click="handleCustom">自定义表格</el-button>-->
          </div>
        </div>

        <el-table
          :data="tableDataList"
          :max-height="tableHeight"
          ref="companylabelList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            :label="item.label"
            :align="item.align?item.align:`center`"
            v-for="(item, index) in tableColumns"
            :key="index"
            :prop="item.key"
            :min-width="item.minWidth ? item.minWidth : ``"
            :fixed="item.fixed ? item.fixed : false"
            :show-overflow-tooltip="true"
          >
            <!--用于表格自定义-->
            <template slot-scope="scope">
              <div v-if="item.key=='name'">
                <div class="userInfo">
                  <img src="../../../assets/images/profile.jpg"/>
                  <div class="name">小城红</div>
                  <div class="label">@志新</div>
                </div>
              </div>
              <div class="label-list" v-else-if="item.key=='label'">
                <span>未入VIP群</span>
                <span>持续7天未发言</span>
                <span>1000</span>
              </div>

              <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <div class="table-footer">
        <div class="footer-left">
          <div class="chooseAll">选择全部</div>
          已选<span>13</span>个
        </div>
        <div class="footer-right">
          <el-button type="primary"  size="small" plain v-hasPermi="['IntelligentOperationList:move']">移动到其他标签</el-button>
          <el-button type="primary"  size="small" plain v-hasPermi="['IntelligentOperationList:move']">从标签里删除</el-button>
        </div>
      </div>
    </div>
    <selectPeople v-if="showSelectPeople" :visableIf.sync="showSelectPeople"></selectPeople>
    <echartData v-if="showEechartData" :visableIf.sync="showEechartData"></echartData>
  </div>
</template>

<script>
import {listUser, delUser,} from "@/api/system/user";

export default {
  name: "IntelligentOperationList",
  components: {
    'multipleSelect': () => import('@/components/MultipleSelect/index.vue'),
    'selectPeople': () => import('@/views/customerOperationsMgt/customerLabelMgt/selectPeople.vue'),
    'echartData': () => import('@/views/customerOperationsMgt/customerLabelMgt//echartData.vue'),//历史标签
  },
  data() {
    return {
      showEechartData: false,
      showSelectPeople: false,
      active: 0,
      treeActive: 0,
      smallActive: 0,
      userList: [
        {
          value: 1,
          label: '锐行',
          name: '小微',
        },
        {
          value: 2,
          label: '锐行',
          name: '小红',
        },
      ],
      lableOpt: [
        {
          value: 1, label: '客户等级', children: [
            {value: 3, label: '核心',},
            {value: 4, label: '重要',},
            {value: 5, label: '一般',}
          ]
        },
        {
          value: 2, label: '客户等级2', children: [
            {value: 6, label: '可爱',},
            {value: 7, label: '知性',},
            {value: 8, label: '性感',}
          ]
        }
      ],
      tablist: [
        {value: 1, label: '行为标签', icon: 'label-active', activeIcon: 'label-active-active'},
        {value: 2, label: '生命周期标签', icon: 'label-live', activeIcon: 'label-live-active'},
        {value: 3, label: '客户价值标签', icon: 'label-value', activeIcon: 'label-value-active'},
        {value: 4, label: '时间进程标签', icon: 'label-time', activeIcon: 'label-time-active'},
        {value: 5, label: '自定义标签', icon: 'label-edit', activeIcon: 'label-edit-active'},
      ],
      treeList: [
        {
          value: 1, label: '社群行为',
          showChildren: true,
          children: [
            {value: 3, label: '未入常规群',},
            {value: 4, label: '已入常规群',},
          ]
        },
        {
          value: 2, label: '私聊活跃度',
          showChildren: false,
          children: [
            {value: 5, label: '新好友一小时未发言',},
            {value: 6, label: '持续三天未发言',},
          ]
        },
      ],

      showExportPage: false,//导出
      tableHeight: 530,
      tableColumns: [
        {key: 'name', label: `客户名`, visible: true, minWidth: 150, fixed: true, align: 'left'},
        {key: 'label', label: `企微标签`, visible: true, minWidth: 150, fixed: false},
        {key: 'label', label: `智能标签`, visible: true, minWidth: 150, fixed: false},
      ],
      tableDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,//用户id
        userName1: null,

      },
      total: 8, // 表格的总条数
    };
  },
  created() {
    // this.getList();
    this.tableDataList = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        name: '小红',
        label: '18207418337',
        operate: true,
      }
      this.tableDataList.push(obj);
    }
  },
  methods: {
    handleViewData() {
      this.showEechartData = true;
    },
    getAcitve(index) {
      this.active = index;
    },
    handerAdd(type) {
      this.$router.push({
        path: '/IntelligentOperationMgt/inoperationMgt/automaticLabelingMgt',
      })
    },
    getTreeActive(index, sindex) {
      this.treeActive = index;
      this.smallActive = sindex;
    },
    isOpenNode(index) {
      this.treeList[index].showChildren = !this.treeList[index].showChildren;
    },
    openNewWindow() {
      window.open('https://work.weixin.qq.com/', '_blank'); // 这里将会打开一个名为"_blank"的新窗口并跳转到指定链接
    },
    handleDragEnd(draggingNode, dropNode, dropType, ev) {
      console.log('tree drag end: ', dropNode && dropNode.label, dropType);
    },
    handleAddUser() {
      this.showSelectPeople = true;
    },

    showLabel() {
      this.showSelectLabelPage = true;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        })
        console.log('multipleSelection', this.multipleSelection);
      }
    },
    handleView(row) {
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const userIds = row.userId || this.ids;
      // this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function () {
      //   return delUser(userIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {
      // });
      this.$msgBox.showMsgBox({
        title: "是否确认删除？",
        content: "该企微号正在执行服务，删除将会使该号从操作中释放，导致部分功能无法正常使用，请谨慎选择。*如该号已加入在线聊天，成功删除后，聊天记录会被一并删除，重新登录后无法恢复。",
      })
        .then(async (val) => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleNumberDelete() {
      // const userIds = row.userId || this.ids;
      // this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function () {
      //   return delUser(userIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {
      // });
      this.$msgBox.showMsgBox({
        title: "是否确认删除？",
        content: "该企微号正在执行服务，删除将会使该号从操作中释放，导致部分功能无法正常使用，请谨慎选择。*如该号已加入在线聊天，成功删除后，聊天记录会被一并删除，重新登录后无法恢复。",
      })
        .then(async (val) => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.showExportPage = true;
    },
    handleCustom() {
      this.showCustomListPage = true;
    },
    handerTableLabel() {
      console.log('点击了打开标签',);
      this.showTableLabel = true;
    },
    handleSelectSmartTags() {
      //打开智能标签
      this.showSelectSmartTags = true;
    },
  }
};
</script>
<style lang="scss" scoped>
.treeList {
  display: flex;
  color: rgba(0, 0, 0, .85) !important;
  width: 100%;
  margin-top: 10px;
  font-size: 14px;
  flex-direction: column;

  li {
    list-style: none;
    width: 100%;

    .title {
      line-height: 20px;
      padding: 5px 0px;
      display: flex;
      justify-content: space-between;
      margin: 5px;
      cursor: pointer;

      i {
        padding-right: 5px;
      }
    }

    dl {
      padding: 0px;
      margin: 0px;

      dd {
        padding: 0px;
        margin: 0px;
        line-height: 20px;
        padding: 5px 0px;
        margin: 5px 0px;
        cursor: pointer;
        padding-right: 60px;
        position: relative;

        .number {
          position: absolute;
          right: 10px;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          top: 0;
          color: rgba(0, 0, 0, .45);
        }

        i {
          padding-right: 5px;
        }

        &.treeActive {
          background: #ebf2ff !important;
          border-radius: 4px;
        }

      }
    }
  }
}

.tablist {
  display: flex;
  justify-items: center;
  border-left: none;
  border-radius: 4px 0 0 4px;
  position: relative;
  margin: 0;
  align-items: center;
  margin-left: 20px;

  &:after {
    content: '';
    position: absolute;
    left: -40px;
    right: -40px;
    bottom: 0px;

  }

  li {
    margin: 0;
    padding: 8px 16px;
    background: #fafafa;
    border: 1px solid #e9e9e9;
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    list-style: none;
    font-size: 14px;
    margin: 0px 5px;
    cursor: pointer;

    &.active {
      border-color: #fff;
      color: #3070ff;
      background: #fff;
    }
  }
}

.container-big {
  display: flex;
  height: calc(100vh - 80px);
  margin: 12px;
  flex-direction: column;


  .container-right {
    flex: 1;
    background: #fff;
  }
}


.content-big {
  height: calc(100vh - 180px);
  overflow-y: auto;
  background: #fff;
  display: flex;

  .content-left {
    width: 260px;
    border-right: 1px solid #eee;
    height: 100%;
    padding: 0 16px 16px;
    overflow-y: auto;


  }

  .content-tabel {
    flex: 1;
    padding: 0px 15px;
  }

  .el-form {
    background: #fff;
    border-radius: 8px;
    margin-top: -1px;

    .el-button {
      margin-right: 10px;
    }

    .el-form-item {
      margin-bottom: 0px;

      .right-big {
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        padding-left: 11px;

        > span {
          color: #777;
          width: 89px;
          display: inline-block;
          white-space: nowrap;
        }

        .el-select {
          width: 138px;

          ::v-deep .el-input__inner {
            border: none;
          }
        }

        .el-input {
          width: 138px;

          ::v-deep .el-input__inner {
            border: none;
          }
        }

        ::v-deep .el-date-editor {
          border: none;
        }
      }

    }
  }

  .content-tabel {
    background: #fff;


    .el-table {
      margin-bottom: 20px;
    }
  }

  .pagination-container {
    height: 60px;
  }
}

.table-footer {
  position: fixed;
  left: 500px;
  right: 12px;
  bottom: 0;
  height: 56px;
  padding: 12px 16px;
  border-top: 1px solid #e9e9e9;
  background: #fff;
  z-index: 2;
  display: flex;
  justify-content: space-between;

  .footer-left {
    display: flex;
    align-items: center;

    .chooseAll {
      color: #5993ff;
      margin-right: 10px;
    }

    span {
      margin: 0px 10px;
      color: #5993ff;
    }
  }

  .footer-right {
    .el-dropdown {
      margin-right: 10px;

      .el-button--primary {
        border-radius: 4px;
        color: rgba(0, 0, 0, .65);
        border: 1px solid #e9e9e9;
        background: #fff;
      }
    }
  }
}

.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.label-list {
  label {
    font-size: 14px;
    line-height: 1.5715;
    word-wrap: break-word;
    font-weight: 400;
  }

  span {
    margin: 4px 4px 4px 0;
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    background: #f0f0f0;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
    padding: 0px 7px;
    display: inline-block;

  }
}

::v-deep .el-tree {
  font-size: 14px;

  ::v-deep .el-tree-node__content {
    height: 30px;
    line-height: 30px;
  }
}

.left-title {
  font-size: 14px;
  font-weight: bold;
  background: #fff;
  padding-top: 16px;
  padding-bottom: 12px;

}

.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}

.flex {
  .search {
    margin-right: 10px;
  }
}

::v-deep .el-tree-node__content {
  padding: 5px 0px !important;
  height: auto;
}

.content-title {
  font-size: 14px;
  height: 40px;
  line-height: 40px;
  font-weight: bold;

}

.el-form {
  margin-bottom: 10px;
}

.table-footer {
  position: fixed;
  left: 500px;
  right: 12px;
  bottom: 0;
  height: 56px;
  padding: 12px 16px;
  border-top: 1px solid #e9e9e9;
  background: #fff;
  z-index: 2;
  display: flex;
  justify-content: space-between;

  .footer-left {
    display: flex;
    align-items: center;

    .chooseAll {
      color: #5993ff;
      margin-right: 10px;
    }

    span {
      margin: 0px 10px;
      color: #5993ff;
    }
  }

  .footer-right {
    .el-dropdown {
      margin-right: 10px;

      .el-button--primary {
        border-radius: 4px;
        color: rgba(0, 0, 0, .65);
        border: 1px solid #e9e9e9;
        background: #fff;
      }
    }
  }
}

.form-big {
  display: flex;
  justify-content: space-between;
}
</style>
